import React from 'react';
import {Card, Table} from "antd";
import outboundDeliveryOrderColumns from "columns/OdoColumns";
import LogFactory from "log/LogFactory";
import {OutboundDeliveryOrder} from "type/OutboundDeliveryOrder";

import useAsyncEffect from "hooks/useAsyncEffect";
import OdoDataConvert from "convert/OdoDataConvert";
import {requestClientList, requestEngineInfo, requestOdoList} from "../RequestHandler";

const log = LogFactory.getLog("OdoComponent");
const OdoComponent = () => {
    const [data,setData] = React.useState<OutboundDeliveryOrder[]>([]) ;

    useAsyncEffect(
        async () => {
            const [odoRes,clientRes,engineRes] = await Promise.all([
                requestOdoList(),
                requestClientList(),
                requestEngineInfo()
            ]) ;
            log.debug("并行执行结果",odoRes,clientRes,engineRes) ;
            if (odoRes.success) {
                const dataConvert = new OdoDataConvert(odoRes.data) ;
                clientRes.success && dataConvert.convertClient(clientRes.data) ;
                engineRes.success && dataConvert.convertEngine(engineRes.data) ;
                dataConvert.convert() ;
                setData(odoRes.data);
            }
        }
    ) ;

    return (
        <Card
            style={{overflow: "hidden"}}
            title="零件出库单列表"
            extra={<a href="#">More</a>}
        >
            {/*<TableToolbar />*/}
            <Table
                scroll={{x: 1300}}
                columns={outboundDeliveryOrderColumns}
                dataSource={data}
                rowKey="key"
                pagination={{pageSize: 20}}
                // size="small"
            />
        </Card>
    );
};

export default OdoComponent;